package com.datuo.dtf.admin.conf;

import com.datuo.dtf.common.exception.BaseServiceException;
import com.datuo.dtf.common.http.HttpResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理类
 * controller层异常无法捕获处理，需要自己处理
 */
@RestControllerAdvice
@Slf4j
public class DefaultExceptionHandler {

    /**
     * 处理所有自定义异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(BaseServiceException.class)
    public HttpResult handleCustomException(BaseServiceException e) {
        log.error(e.getMessage());
        return HttpResult.result(e.getCode(), e.getMessage());
    }
}
